#include <timeheap.h>

static TimeHeap s_timeheap;

class TimerNode : public CallbackObject
{
public:
	TimerNode( int32_t intval )
	{
		set_handler( this, &TimerNode::time_out );
		m_timerid = s_timeheap.register_timerhandle( Time_Value(intval,0), 
			Time_Value(intval,0), this );
		debug_output( "TimerNode(%d) timerid(%d)", intval, m_timerid );
	}
	
	virtual ~TimerNode() throw()
	{
		s_timeheap.unregister_timerhandle( m_timerid );
	}
	
	int32_t time_out( int32_t code, void * data )
	{
		time_t curr = time(NULL);
		debug_output( "timerid(%d) time(%s)", m_timerid, ctime(&curr) );
		return 0;
	}
private:
	int32_t		m_timerid;
};

#define MAX_TIMENODE_COUNT 100000

int main( int argc, char * argv[] )
{
	TimerNode * times[MAX_TIMENODE_COUNT];
	for( int32_t index = 0; index < (int32_t)(MAX_TIMENODE_COUNT); ++index )
	{
		times[index] = new TimerNode(index+1);
	}
	
	while( 1 )
	{
		s_timeheap.timer_poll( Time_Value::timeofday() );
		usleep(10);
	}
	
	return 0;
}
